package net.zjitc.controller;

import net.zjitc.pojo.Admin;
import net.zjitc.pojo.Category;
import net.zjitc.service.AdminService;
import net.zjitc.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
//    @RequestMapping("/list")
//    public ModelAndView findCategoryList() {
//        ModelAndView mv = new ModelAndView();
//
//        List<Category> categoryList = categoryService.findCategoryList();
//        mv.addObject("categoryList",categoryList);
//        mv.setViewName("list");
//        return mv;
//    }
//
//    @PostMapping("/add")
//    public String addCategory(Category category, Model model) {
//        categoryService.addCategory(category);
//        return "redirect:/category/list";
//    }
//    @PostMapping("/delete")
//    public String deleteCategory(int id) {
//        categoryService.deleteCategory(id);
//        return "list";
//    }
//    @PostMapping("/update")
//    public void updateCategory(Category category) {
//        categoryService.updateCategory(category);
//    }
    @RequestMapping("/list")
    public ModelAndView findCategoryList() {
        ModelAndView mv = new ModelAndView();

        List<Category> categoryList = categoryService.findCategoryList();
        mv.addObject("categoryList",categoryList);
        mv.setViewName("list");
        return mv;
    }
}